<?php
if(!isset($_SESSION)) session_start();

if (isset($_REQUEST["section"])) $_SESSION["section"] = $_REQUEST["section"];
if (isset($_REQUEST["area"])) $_SESSION["area"] = $_REQUEST["area"];


$illegal_types = array(".","..");
$area = $_REQUEST["area"];
$section = $_REQUEST["section"];
$module = "{$_SERVER["DOCUMENT_ROOT"]}/media/{$area}/{$section}/";

$files = array();

if (! is_dir($module)) mkdir($module,0,true);

$dirhandler = opendir($module);
$nofiles=0;
while ($file = readdir($dirhandler)) {
        if(! in_array($file,$illegal_types)) {
            $files[$nofiles]=$file;
            $nofiles++;
        }  
}
if ($nofiles==0)$files[$nofiles] = "No media found";

echo json_encode($files);
?>